﻿#include "CClientInstance.h"

#include "../Utils/Utils.h"
#include "../Memory/GameData.h"

int64_t MinecraftGame::getServerEntries() {
	return Utils::Utils::CallVFunc<30, int64_t>(this);
}

bool C_GuiData::isHeliumMessage{false};

void C_GuiData::displayClientMessage(const char8_t *const c, const size_t size) noexcept {
	using displayClientMessage = void(__thiscall *)(const void *, TextHolder_view &);
	static const displayClientMessage displayMessageFunc{reinterpret_cast<displayClientMessage>(Utils::Utils::getBase() + 9295984)};
	if (!GameData::isInGame()) [[unlikely]]
		return;
	static const auto GuiData{GameData::getGuiData()};
	isHeliumMessage = true;
	TextHolder_view text{c, size};
	displayMessageFunc(GuiData, text);
}

void C_GuiData::displayClientMessage(const std::u8string_view a2) noexcept {
	displayClientMessage(a2.data(), a2.size());
}

uintptr_t *mce::TexturePtr::getClientTexture() const {
	return this->clientTexture;
}

vec3_t &LevelRenderer::getOrigin() const {
	return *(vec3_t *)((uintptr_t)this + (0x798));
}

vec3_t &LevelRenderer::getLoader() const {
	return *(vec3_t *)((uintptr_t)this + (0xB74));
}

uintptr_t LevelRenderer::getLevelRendererPlayer() const {
	return reinterpret_cast<uintptr_t>(this) + 0x310;
}

C_Font *MinecraftGame::getTheGoodFontThankYou() const {
	return fontRepository->fontList->fontEntries[7].font;
};

C_Font *MinecraftGame::getTheRandomFontPlease() const {
	return fontRepository->fontList->fontEntries[4].font;
};

C_Font *MinecraftGame::getOldFont() const {
	return fontRepository->fontList->fontEntries[7].font;
};

C_Font *MinecraftGame::getTheBetterFontYes() const {
	return fontRepository->fontList->fontEntries[3].font;
}

C_Font *MinecraftGame::getMCFont() const {
	return mcFont;
}

const bool MinecraftGame::canUseKeybinds() const {
	return canUseKeys;
};

Level *C_ClientInstance::getPointerStruct() const {
	return this->getLevel();
}

glmatrixf *C_ClientInstance::getRefDef() const {
	const uintptr_t _this = reinterpret_cast<uintptr_t>(this);
	// logF("refderf %llX", _this + 0x258);
	return reinterpret_cast<glmatrixf *>(_this + 0x2F0);
};

vec2_t *C_ClientInstance::getMousePos() const {
	const uintptr_t _this = reinterpret_cast<uintptr_t>(this);
	return reinterpret_cast<vec2_t *>(_this + 0x458);
}

vec2_t C_ClientInstance::getFov() const {
	const uintptr_t _this = reinterpret_cast<uintptr_t>(this);
	// vec2_t fov(fovX, fovY);
	return vec2_t{*reinterpret_cast<float *>(_this + 0x678), *reinterpret_cast<float *>(_this + 0x68C)};
}

C_Font *C_ClientInstance::_getFont() const {
	return this->getFont();
}

C_Font *C_ClientInstance::_getRuneFont() const {
	return this->getRuneFont();
}

C_Font *C_ClientInstance::_getUnicodeFont() const {
	return this->getUnicodeFont();
}

C_GuiData *C_ClientInstance::getGuiData() const {
	return (C_GuiData *)*reinterpret_cast<uintptr_t *>(reinterpret_cast<C_GuiData *>(reinterpret_cast<uintptr_t>(this) + 0x4E8));
};

C_LocalPlayer *C_ClientInstance::getLocalPlayer() const {
	uintptr_t ptr{*reinterpret_cast<uintptr_t *>(reinterpret_cast<uintptr_t>(this) + 0xD0)};
	if (ptr > 0x1000000000u && ptr < 0xF00000000000u) [[likely]] {
		C_LocalPlayer *res{*reinterpret_cast<C_LocalPlayer **>(ptr + 0x278)};
		if (reinterpret_cast<uintptr_t>(res) < 0xF00000000000u) [[likely]]
			return res;
	}

	return nullptr;
}
